/*! \file MessagesMap.h
 *	\brief <write description for MessagesMap.h>
 *
 *	created:	2010/09/09
 *	created:	9:9:2010   16:34
 *	filename: 	s:\DNG-Code\Kiev\Modules\Orbit\Common\MessagesMap.h
 *	file path:	s:\DNG-Code\Kiev\Modules\Orbit\Common
 *	file base:	MessagesMap
 *	file ext:	h
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */

#ifndef _protection_MESSAGESMAP_H_
#define _protection_MESSAGESMAP_H_

#pragma once

#include "Functors.h"

namespace tt{
namespace core{

//////////////////////////////////////////////////////////////////////////
template<typename Handler>
class MessageHandlersMapItem
{
public:
	bool operator<(const MessageHandlersMapItem&);
	bool operator==(const MessageHandlersMapItem&);

public:
	mg::serverbox::DelimiterType id;
	Handler handler;
};
template<typename Handler>
bool operator<(const MessageHandlersMapItem<Handler>&, const mg::serverbox::DelimiterType);
template<typename Handler>
bool operator<(const mg::serverbox::DelimiterType, const MessageHandlersMapItem<Handler>&);

template<typename Handler>
class MessageHandlersMapBase
{
public:
	MessageHandlersMapBase();
	~MessageHandlersMapBase();

	void insert(mg::serverbox::DelimiterType, const Handler&);

protected:
	Handler* find(mg::serverbox::DelimiterType);

protected:
	typedef MessageHandlersMapItem<Handler> Item;
	typedef std::vector<Item> Items;
	Items m_items;
};

//////////////////////////////////////////////////////////////////////////
template<typename Handler>
class MessageHandlersMap : public MessageHandlersMapBase<Handler>
{
};

//////////////////////////////////////////////////////////////////////////
template<>
class MessageHandlersMap<Functor0> : public MessageHandlersMapBase<Functor0>
{
public:
	bool operator() (mg::serverbox::DelimiterType);
};

//////////////////////////////////////////////////////////////////////////
template<typename Arg1>
class MessageHandlersMap< Functor1<Arg1> > : public MessageHandlersMapBase< Functor1<Arg1> >
{
public:
	bool operator() (mg::serverbox::DelimiterType, Arg1);
};

//////////////////////////////////////////////////////////////////////////
template<typename Arg1, typename Arg2>
class MessageHandlersMap< Functor2<Arg1, Arg2> > : public MessageHandlersMapBase< Functor2<Arg1, Arg2> >
{
public:
	bool operator() (mg::serverbox::DelimiterType, Arg1, Arg2);
};

} //namespace core
} //namespace tt
#include "MessageHandlersMap.inl"

#endif //_protection_MESSAGESMAP_H_